package com.spring.controller;


import com.spring.pojo.SysUser;
import com.spring.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * @author 67030
 */
@Controller
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping(value="/login",method = RequestMethod.GET)
    public String getLogin(){
        return "login";
    }
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(HttpServletRequest req, HttpServletResponse res){
        String userCode=req.getParameter("name");
        String psw=req.getParameter("psw");
        SysUser user=userService.login(userCode,psw);
        if(user==null){
            return "index";
        }
        System.out.println(user.toString());

        return "../index";
    }
    @RequestMapping(value="/register",method = RequestMethod.GET)
    public String getReg(){
        return "register";
    }
    @RequestMapping(value="/register",method = RequestMethod.POST)
    public String register(HttpServletRequest req, HttpServletResponse res){
        String userCode=req.getParameter("name");
        String psw=req.getParameter("psw");
        String name=req.getParameter("name");
        SysUser NewUser=userService.register(userCode,psw,name);
        if(NewUser==null){
            return "register";
        }
        return "../index";
    }
    UserController(){
        System.out.println("OK");
    }
}
